<?php
namespace app\index\validate;

use think\Validate;
use think\Db;
use app\index\model\User;

class Login extends Common
{
    protected $rule = [
        'vercode' => 'require|checkCode',
        'password'=>'require',
        'loginName'=>'require|checkLogin'
       
    ];

    protected $message  =   [
        'vercode.require' => '人类验证错误'
    ];


    protected function checkLogin($value,$rule,$data)
    {
        // $res = Db::table('fly_user')->where('phone',$data['loginName'])->find();

        $res = User::get(['phone'=>$data['loginName']]);

        if(!$res){
            $res = User::get(['email'=>$data['loginName']]);
        }

        if(!$res){
            return "用户或者密码错误";
        }

        if($res->password===fly_md5($data['password'])){

            if($res->status){
                return "帐号异常，请充值";
            }

            session('nickname',$res->nickname);
            session('uid',$res->uid);
            session('face',$res->face);
            return true;
        }else{
            return "用户或者密码错误";
        }
    }

}
